package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.common.util.MD5;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.model.user.UserInfo;
import com.atguigu.gmall.user.mapper.UserInfoMapper;
import com.atguigu.gmall.user.service.UserInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: gmall-parent
 * @author: Mr.Zhuo
 * @create: 2022-04-12 22:45
 **/
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;



    /**
     * // 校验数据库中的用户数据
     *
     * @param userInfo
     * @return
     */
    @Override
    public UserInfo login(UserInfo userInfo) {
        // 获取登录名字
        String loginName = userInfo.getLoginName();

        // 进行密码加密   拓展我们可以加盐
        String encrypt = MD5.encrypt(userInfo.getPasswd());

        // 创建查询条件
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("login_name", loginName);
        queryWrapper.eq("passwd", encrypt);

        UserInfo selectOne = userInfoMapper.selectOne(queryWrapper);
        // 返回数据
        return selectOne;
    }
}
